package com.ctl.test;

import java.sql.ResultSet;
import java.sql.SQLException;

public class PageBean {
	private int curPage; // 当前页
	private int pageCount; // 总页数
	private int rowsCount; // 总行数
	private int pageSize = 4; // 每页多少行

	/**
	 * 生成get，set方法
	 * 
	 * @return
	 */
	public int getCurPage() {
		return curPage;
	}

	public void setCurPage(int curPage) {
		this.curPage = curPage;
	}

	public int getPageCount() {
		return pageCount;
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	public int getRowsCount() {
		return rowsCount;
	}

	public void setRowsCount(int rowsCount) {
		this.rowsCount = rowsCount;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	/**
	 * 分页数计算
	 * 
	 * @param rows
	 */
	public PageBean(int rows) {
		this.setRowsCount(rows);
		if (this.rowsCount % this.pageSize == 0) {
			this.pageCount = this.rowsCount / this.pageSize;
		} else if (rows < this.pageSize) {
			this.pageCount = 1;
		} else {
			this.pageCount = this.rowsCount / this.pageSize + 1;
		}
	}

	/**
	 * 保证了rs.next()不会跳过第一条	
	 * @throws SQLException 
	 */
	public static void main(String[] args) throws SQLException {
		ResultSet rs = null;
		if (!rs.next()) {
			/* 结果集为空的操作 */
		} else {
			do {
				/* 有结果集的操作 */
			} while (rs.next());
		}
	}

}
